import {NgModule, ErrorHandler, Inject} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {IonicApp, IonicModule, IonicErrorHandler} from 'ionic-angular';
import {MyApp} from './app.component';

import {AboutPage} from '../pages/about/about';
import {AboutPage2} from '../pages/about2/about';


import {StatusBar} from '@ionic-native/status-bar';
import {SplashScreen} from '@ionic-native/splash-screen';
import {QRScanner} from "@ionic-native/qr-scanner";
import {ScanPage} from "../pages/scan/scan";
import {Geolocation} from "@ionic-native/geolocation";
import {HttpClientModule} from '@angular/common/http';
import {Base} from "../common/base.js";
import {CoordinateConvertor} from "../common/coordinate-convertor";

import {File} from "@ionic-native/file";
import {FileTransfer} from "@ionic-native/file-transfer";
import {Camera} from "@ionic-native/camera";
import { ImagePicker } from '@ionic-native/image-picker';
import {Diagnostic} from "@ionic-native/diagnostic";
import {AppVersion} from '@ionic-native/app-version';
import {InAppBrowser} from '@ionic-native/in-app-browser';
import {AlertController} from 'ionic-angular';
import {NewHomePage} from '../pages/newhome/newhome'
import {switchProjectPage} from '../pages/newSwitchProject/newSwitchProject';
import {TrapPage} from '../pages/newTrap/newTrap'
import {DryPage} from '../pages/newDry/newDry';
import {DeadtreePage} from '../pages/newDeadTree/newDeadTree';
import {EnemyPage} from '../pages/newEnemy/newEnemy';
import {TrackPage} from '../pages/newTrack/newTrack';
import {NewStaticsPage} from '../pages/new-statics/new-statics';
import {TrapQueryPage} from '../pages/trap-query/trap-query';
import {DeadTreesQueryPage} from '../pages/dead-trees-query/dead-trees-query';
import {InjectQueryPage} from '../pages/inject-query/inject-query';
import {EnemyQueryPage} from '../pages/enemy-query/enemy-query';
import {TrackQueryPage} from '../pages/track-query/track-query';
import {Base64} from '@ionic-native/base64';
import {AppAvailability} from '@ionic-native/app-availability';
import {NewMedicinePage} from '../pages/new-medicine/new-medicine';
import {MedicineQueryPage} from '../pages/medicine-query/medicine-query';
import {Network} from '@ionic-native/network';
import {NetworkProvider} from "../network/NetworkProvider";
import {StatisDetailPage} from "../pages/statis-detail/statis-detail";

export class MyErrorHandler implements ErrorHandler {
    constructor(
        @Inject(AlertController) private alerts: AlertController,
        @Inject(SplashScreen) public splashScreen: SplashScreen,
        private base: Base
    ) {
    }

    handleError(err: any): void {
        // do something with the error
        console.log(err);
        // alert(JSON.stringify(err));
        // alert(JSON.parse(err));
        //  alert(JSON.stringify(err));
        // alert(String(err));
        // this.base.logger(JSON.stringify(err),"error.txt");
        // this.base.logger(JSON.parse(err),"error.txt");
        this.base.logger(JSON.stringify(err),"error.txt");
    }
}

@NgModule({
    declarations: [
        MyApp,
        AboutPage,
        TrapQueryPage,
        DeadTreesQueryPage,
        InjectQueryPage,
        EnemyQueryPage,
        TrackQueryPage,
        NewMedicinePage,
        MedicineQueryPage,
        AboutPage2,
        ScanPage,
        NewHomePage,
        DryPage,
        DeadtreePage,
        StatisDetailPage,
        EnemyPage,
        TrackPage,
        NewStaticsPage,
        TrapPage,
        switchProjectPage
    ],
    imports: [
        BrowserModule,
        HttpClientModule,
        IonicModule.forRoot(MyApp, {
            iconMode: 'ios',
            mode: 'ios',
            backButtonText: '返回'
        })
    ],
    bootstrap: [IonicApp],
    entryComponents: [
        MyApp,
        AboutPage,
        ScanPage,
        NewHomePage,
        DryPage,
        TrapQueryPage,
        DeadTreesQueryPage,
        InjectQueryPage,
        EnemyQueryPage,
        TrackQueryPage,
        NewMedicinePage,
        MedicineQueryPage,
        StatisDetailPage,
        NewStaticsPage,
        DeadtreePage,
        EnemyPage,
        TrackPage,
        switchProjectPage,
        TrapPage,
        AboutPage2,
    ],
    providers: [
        InAppBrowser,
        AppVersion,
        StatusBar,
        SplashScreen,
        QRScanner,
        Geolocation,
        Base,
        CoordinateConvertor,
        AppAvailability,
        Diagnostic,
        Base64,
        Camera,
        File,
        FileTransfer,
        Network,
        NetworkProvider,
        ImagePicker,
        {provide: ErrorHandler, useClass: MyErrorHandler}
    ]
})
export class AppModule {
}
